import {request} from '../utils/request';

// 发送请求 文章列表时 可能需要的参数
export interface postsType {
  id: number;
  thumb_url: string;
  content: string;
  type: number;
  create_time: Date;
  update_time: Date;
  title: string;
  author: string;
}
export interface searchPostsType {
  title?: string;
}

export interface pushPostsType {
  id: number;
  thumb_url: string;
  content: string;
  type: number;
  create_time: string;
  update_time: string;
  title: string;
  author: string;
}
export const posts = async (): Promise<any> => {
  return await request.get('post/list');
};

export const searchPosts = async (data: string): Promise<any> => {
  return await request.post('post/search', data);
};

export const updatePosts = async (data: postsType): Promise<any> => {
  return await request.put(`post/${data.id}`, data);
};

export const createPost = async (data: Partial<postsType>): Promise<any> => {
  return await request.post(`post`, data);
};

export const deletePost = async (id: number) => {
  //  使用 delete传递参数的话 可以这么传 这样后台接收的话是一个 delete/:id 动态的id
  return await request.delete(`post/delete/${id}`);
};
